package com.littlebee.storysuper.activity;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.littlebee.storysuper.R;
import com.littlebee.storysuper.utils.ToastUtil;
import com.littlebee.storysuper.utils.Utils;

import cn.jpush.im.android.api.JMessageClient;
import cn.jpush.im.android.api.event.LoginStateChangeEvent;
import cn.jpush.im.android.api.model.UserInfo;

import static cn.jpush.im.android.api.event.LoginStateChangeEvent.Reason.user_deleted;
import static cn.jpush.im.android.api.event.LoginStateChangeEvent.Reason.user_logout;
import static cn.jpush.im.android.api.event.LoginStateChangeEvent.Reason.user_password_change;

public class UserLogoutEventReceiver  extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        JMessageClient.registerEventReceiver(this);
    }
    @Override
    protected void onDestroy() {
        JMessageClient.unRegisterEventReceiver(this);
        super.onDestroy();
    }
    public void onEvent(LoginStateChangeEvent event){
        LoginStateChangeEvent.Reason reason = event.getReason();//获取变更的原因
        UserInfo myInfo = event.getMyInfo();//获取当前被登出账号的信息
        switch (reason) {
            case user_password_change:
                //用户密码在服务器端被修改
                break;
            case user_logout:
                //用户换设备登录
                ToastUtil.displayShortToast("您的IM已经在其他设备登录 本地已下线");
                Utils.saveUserEntry(null);

                break;
            case user_deleted:
                //用户被删除
                break;
        }
    }

}